<?php

namespace app\api\middleware;

use app\api\model\User;
class Auth
{
    public function handle($request, \Closure $next)
    {
        // 添加中间件执行代码
        $userId = $request->param('userId/d',0);
        $responseData = [
            'count'=>1,
            'data'=>[],
            'msg'=>'用户信息错误',
            'code'=>6
        ];
        if($userId<=0){
        	return json($responseData);
        }
    	$userInfo = (new User)->find($userId);
    	if(!$userInfo){
    		return json($responseData);
    	}
    	$request->userInfo = $userInfo;
        return $next($request);
    }
}